﻿using RpcHelper;
using SqlExecHelper;
using SqlExecHelper.Insert;

namespace Wedonek.RpcStore.Service.DAL
{
        internal class DictateNodeRelationDAL : SqlBasicClass
        {
                public DictateNodeRelationDAL () : base ("DictateNodeRelation", "RpcExtendService")
                {

                }

                public long[] GetParents (long subId)
                {
                        return base.GetOutColumn<long, long> ("SubId", subId, "ParentId");
                }
                public long[] GetSubs (long parentId)
                {
                        return base.GetOutColumn<long, long> ("ParentId", parentId, "SubId");
                }
                public void Clear (long subId)
                {
                        if (!base.Drop ("SubId", subId))
                        {
                                throw new ErrorException ("rpc.dictate.relation.drop.error");
                        }
                }
                public void Drop (long[] subId)
                {
                        base.Drop ("SubId", subId);
                }

                public void Add (long subId, long[] parentId)
                {
                        IInsertTable table = base.InsertTable (parentId.Length, 2);
                        table.Column = new TableColumn[]
                        {
                                new TableColumn("SubId", System.Data.SqlDbType.BigInt),
                                new TableColumn("ParentId", System.Data.SqlDbType.BigInt)
                        };
                        parentId.ForEach (a =>
                        {
                                table.AddRow (subId, a);
                        });
                        table.Save ();
                }
        }
}
